#include <cmath>
#include <iostream>

#include "gtest/gtest.h"

#include "../RandomRespSolver.h"

// static double TrapzIntegralTest(double x0, double x1, double y0, double y1) {
//     return 0.5 * (y0 + y1) * (x1 - x0);
// }

TEST (TrapzIntegralTest, SimpleCase)
{
    double x0 = 0.0;
    double x1 = 2.0;
    double y0 = 1.0;
    double y1 = 3.0;

    // 手工算一下结果：积分 = (1+3)/2 * (2-0) = 4.0
    double expected = 4.0;
    double result   = RandomRespSolver::TrapzIntegral (x0, x1, y0, y1);

    EXPECT_DOUBLE_EQ (result, expected);
}

TEST (TrapzIntegralTest, ZeroWidth)
{
    double x0 = 1.0;
    double x1 = 1.0;
    double y0 = 5.0;
    double y1 = 10.0;

    // 宽度为0，积分必然是0
    double expected = 0.0;
    double result   = RandomRespSolver::TrapzIntegral (x0, x1, y0, y1);

    EXPECT_DOUBLE_EQ (result, expected);
}